/**
 * 
 */
package com.socialnetwork.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.socialnetwork.security.pwd.PwdEncryptor;
import com.socialnetwork.user.model.User;
import com.socialnetwork.user.service.UserService;

/**
 * @author asoundar
 *
 */
@Controller
public class Registration {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping(value = "/SignUp", method = RequestMethod.GET)
	public ModelAndView signUpPage() {
		return new ModelAndView("user/registration");
	}
	
	@RequestMapping(value = "/SignUp", method = RequestMethod.POST)
	public String addUser(@ModelAttribute("user")User user, BindingResult result) {

		user.setPassword(PwdEncryptor.encrypt(user.getPassword()));
		userService.addUser(user);

		return "redirect:/SignUp";
	}
	
}
